/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webaccess.retailws.Util;

import com.webaccess.retailws.Bean.ImageBean;
import com.webaccess.retailws.Delegate.AdminDelegate;
import org.apache.struts.upload.FormFile;
import com.webaccess.retailws.Util.CommonUtil;

/**
 *
 * @author Owner
 */
public class AdminUtil {

    CommonUtil commUtil = null;
    AdminDelegate admnDelegate = null;
    ImageBean imagBean = null;

    public AdminUtil() {
        commUtil = new CommonUtil();
    }

    public String uploadFile(FormFile homePageImage, String filePath) {
        return commUtil.uploadFile(homePageImage, filePath);
    }

    public String saveImage(long imageId, String imageName, String homePageImageName, String imageDetail) {
        admnDelegate = new AdminDelegate();
        String SUCCESS = "";
        try {
            imagBean = new ImageBean();
            imagBean.setImageId(imageId);
            imagBean.setImageName(imageName);
            imagBean.setHomePageImageName(homePageImageName);
            imagBean.setImageDetail(imageDetail);
            boolean isImageSaved = admnDelegate.saveImage(imagBean);
            if (imageId == 0) {
                if (isImageSaved == false) {
                    SUCCESS = "saveimagefailure";
                } else {
                    SUCCESS = "imagesuccess";
                }
            } else {
                if (isImageSaved == false) {
                    SUCCESS = "updateimagefailure";
                } else {
                    SUCCESS = "imagesuccess";
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return SUCCESS;
        }
    }
}
